﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASPPatterns.Chap3.Layered.Service
{
    public class ProductService
    {
        private Model.ProductService _productService;

        public ProductService(Model.ProductService productService)
        {
            this._productService = productService;
        }

        public ProductListResponse GetAllProductsFor(ProductListRequest productListRequest)
        {
            ProductListResponse productResponse = new ProductListResponse();
            try
            {
                IList<Model.Product> productEntitis = _productService.GetAllProductFor(productListRequest.CostomerType);
                productResponse.Products = productEntitis.ConvertToProductListViewMode();

                productResponse.Success = true;

            }
            catch (Exception Ex)
            {
                productResponse.Success = false;
                productResponse.Message = "An error occurred!";
            }
            return productResponse;
        }
    }
}
